﻿using System.Data;

namespace smp.QueryDb
{
    internal class Parameter : IParameter
    {
        private readonly string _name;
        private readonly DbType _dataType;
        private readonly object _value;
        private readonly ParameterDirection _direction;

        internal Parameter(string name, DbType dataType, object value)
        {
            _name = name;
            _dataType = dataType;
            _value = value;
            _direction = ParameterDirection.Input;
        }

        internal Parameter(string name, DbType dataType, object value, ParameterDirection direction)
        {
            _name = name;
            _dataType = dataType;
            _value = value;
            _direction = direction;
        }

        internal void AssignToCommand( IDbCommand command)
        {
            var parameter = command.CreateParameter();
            parameter.DbType = _dataType;
            parameter.Direction = _direction;
            parameter.ParameterName = _name;
            parameter.Value = _value;
            command.Parameters.Add(parameter);
        }

        #region Implementation of IParameter

        public string Name { get { return _name; } }

        public DbType DataType { get { return _dataType; } }

        public object Value { get { return _value; } }

        public ParameterDirection Direction { get { return _direction; } }

        #endregion
    }
}
